package com.aistar.servlet;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "Test3Servlet",urlPatterns = "/test3")
public class Test3Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String pname=  request.getParameter("pname");
        String proPrice=  request.getParameter("pprice");
        System.out.println("pname:"+pname +",pprice:"+proPrice);


        JSONObject jsonObject = new JSONObject();//map

        jsonObject.put("status",200);
        jsonObject.put("message","ok");
        jsonObject.put("result","数据查询成功");

        response.setContentType("text/html;charset=utf-8"); //注意此处要将响应中的JSON数据 转码为utf-8,否则会中文乱码
        response.getWriter().print(jsonObject);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
